import axios from 'axios';
import api_top from './path';
// 支持async/await用法
// 获取banner
export const getBanner = async () => {
    try {
      const response = await axios.get(api_top.path+'/banner');
      return response.data;
    } catch (error) {
      console.error('获取banner失败:', error);
      throw error;
    }
};
//修改图片信息
export const amend_img = async (data) => {
  try {
    console.log('发送修改请求:', data); // 添加日志
    const response = await axios.post(api_top.path + '/amend', data, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
    console.log('修改响应:', response.data); // 添加日志
    return response.data;
  } catch (error) {
    console.error('修改失败:', error.response?.data || error.message);
    throw error;
  }
};
// 删除图片
export const delete_img = async (data) => {
  try {
    const response = await axios.post(api_top.path + '/delete', data, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
    console.log(response.data);
    return response.data;
    
    
  } catch (error) {
    console.error('删除失败:', error.response?.data || error.message);
    throw error;
  }
};
// 获取卡图片列表
export const ka_img_list = async () => {
  try {
    const response = await axios.get(api_top.path + '/ka_img');
    console.log(response.data);
    return response.data;
  } catch (error) {
    console.error('获取图片列表失败:', error);
    throw error;
  }
}
// 上传卡图片
export const upka_text = async (data) => {
  try {
    const response = await axios.post(api_top.path + '/ka_text', data, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
    console.log(response.data);
    return response.data;
  } catch (error) {
    console.error('上传失败:', error.response?.data || error.message);
    throw error;
  }
};

//修改卡信息
export const delete_ka = async (data) => {
  try {
    const response = await axios.post(api_top.path + '/delete_ka', data, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
    return response.data;
  } catch (error) {
    console.error('删除卡信息失败:', error);
    throw error;
  }
}
export const search_ka = async (data) => {
  try {
    const response = await axios.post(api_top.path + '/search', data, {
      headers: {
        'Content-Type': 'application/json'
      }
    });
    return response.data;
  } catch (error) {
    console.error('查询失败:', error);
    throw error;
  }
}


const api = {
    getBanner,
    amend_img,
    delete_img,
    ka_img_list,
    upka_text,
    delete_ka,
    search_ka
}
export default api;
